We can now think about constructing our lock. The program will repeatedly wait for a number on the keypad and compare it with a value held in EEPROM. If the two match it will open the bolt (by setting LA4 high). If the two don't match the lock will not do anything.

On the right you can see the requirements and some hints to go on. Try to use portions of exercises 71-74 to create a program which does what is required.

 

Requirement

Hint

The program should repeatedly wait for a number.

You should use a while loop to read in the number and compare it with the correct one.

The number should not be displayed as the user enters it.

You should remove the display_number call in get value and replace it with something which indicates that a digit has been pressed.

The program should compare the number entered with one held in EEPROM.

You can use the code above which reads and stores integers in EEPROM.

The program should fire the lock if the numbers match.

The simplest part of the program will be the comparison between the number entered and the correct number. If the two match you should set the lock_timer value so that the relay is fired. If the two don't match your program should indicate that entry has not been allowed.

You need a way to input the actual key number.

You need to have a way that you can get the key number into the lock. I would suggest that you have two key numbers. The first opens the door and the second puts you into "setup" mode. When in setup the system will accept a new key value and store it. For extra security you could make it possible to enter a new "setup" number as well.